home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / activate.zip / ACT-NDOS.C < prev    next >
C/C++ Source or Header  |  1992-12-04  |  2KB  |  87 lines

  1. /*
  2.  *  Activate.c (v1.01)
  3.  *
  4.  *  NON-DOS routines for reading / writing 1st sector of hard drives
  5.  *
  6.  *  Developed under Coherent v4.0.0 - you may need to change the device
  7.  *  names of the hard drive(s) to suit your own system
  8.  *
  9.  */
  10.  
  11.  
  12. /*
  13.  *  Reads in the first 512 bytes of the given device into the
  14.  *  buffer (global variable) and extracts partition table info from the
  15.  *  sector (partn tbl starts at 0x1BE, 4 entries of 0x10 bytes plus a 2
  16.  *  byte signature at end. Returns 0 if read OK, non-zero otherwise.
  17.  *
  18.  */
  19.  
  20. int read_partition_table(partn, drive)
  21. partition_table *partn;
  22. char *drive;
  23. {
  24.   int status;
  25.   FILE *dr;
  26.  
  27.   dr = fopen(drive, "rb"); 
  28.   if(dr == NULL)
  29.   {
  30.     printf("\nerror opening drive %s", drive);
  31.     exit(1);
  32.   }
  33.   status = fread(buffer, sizeof(byte), 512, dr);
  34.   memmove(partn, (buffer + 0x1BE), sizeof(partition_table));
  35.  
  36.   return status;
  37. }
  38.  
  39.  
  40. /*
  41.  *  Does the reverse of read_partition_table() - writes a new partition
  42.  *  table into the relevent bit of buffer (the last 74 bytes) and writes
  43.  *  the whole 512 bytes to the 1st sector of the specified Hard Drive
  44.  *
  45.  */
  46.  
  47.  
  48. int write_partition_table(partn, drive)
  49. partition_table partn;
  50. char *drive;
  51. {
  52.   int status;
  53.   FILE *dr;
  54.  
  55.   memmove((buffer + 0x1BE), &partn, sizeof(partition_table));
  56.   
  57.   dr = fopen(drive, "wb");
  58.   if(dr == NULL)
  59.   {
  60.     printf("\nError opening drive %s for writing\n", drive);
  61.     exit(1);
  62.   }     
  63.   status = fwrite(buffer, sizeof(byte), 512, dr);
  64.  
  65.   return status;
  66. }
  67.  
  68.  
  69. /*
  70.  * Determines how many Hard drives the BIOS is aware of by trying to read
  71.  * the Master Boot sector of each Hard drive starting from 0x80 (1st disk)
  72.  * contines to read drives (0x81, 0x82, etc) until it receives an error,
  73.  * after which it assumes that all physical drives have been read.
  74.  *
  75.  * Returns number of drives which it has detected.
  76.  *
  77.  */
  78.  
  79. int determine_number_of_drives()
  80. {
  81.   /* I don't know how to implement the proper calls (yet!) (Turbo C
  82.      makes things so easy! <g>), so the quick and dirty way of doing 
  83.      this is just to return a predefined constant */
  84.  
  85.   return(NUM_DRIVES);
  86. }
  87.